home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc Development Framework / ODFDev / ODF / Found / FWExcLib / Sources / FWPostEx.cpp < prev    next >
Encoding:
Text File  |  1995-11-08  |  2.5 KB  |  98 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWPostEx.cpp
  4. //    Release Version:    $ 1.0d11 $
  5. //
  6. //    Copyright:    (c) 1993, 1995 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "FWFound.hpp"
  11.  
  12. #ifndef   FWPOSTEX_H
  13. #include "FWPostEx.h"
  14. #endif
  15.  
  16. #ifndef   FWPRIMEM_H
  17. #include "FWPriMem.h"
  18. #endif
  19.  
  20. #ifndef   FWPRIDEB_H
  21. #include "FWPriDeb.h"
  22. #endif
  23.  
  24. #ifndef FWEXCDEF_H
  25. #include "FWExcDef.h"
  26. #endif
  27.  
  28. #if FW_LIB_EXPORT_PRAGMAS
  29. #pragma lib_export on
  30. #endif
  31.  
  32. #ifdef FW_BUILD_MAC
  33. #pragma segment BEL
  34. #endif
  35.  
  36.  
  37. FW_SPrivPostedExceptionGlobals FW_CPostedException::gGlobals;    
  38.  
  39.  
  40. //----------------------------------------------------------------------------------------
  41. //    FW_CPostedException::GetPostedExceptionGlobals
  42. //----------------------------------------------------------------------------------------
  43.  
  44. FW_SPrivPostedExceptionGlobals& FW_CPostedException::GetPostedExceptionGlobals()
  45. {
  46. //    FW_SPrivPostedExceptionGlobals *globals = (FW_SPrivPostedExceptionGlobals*)
  47. //                FW_CPrivTaskGlobals::GetTaskGlobals(kPostedExceptionGlobals);
  48.     FW_SPrivPostedExceptionGlobals *globals = &gGlobals;
  49.     if (globals->gInitialized == 0)
  50.         Initialize(*globals);
  51.     return *globals;
  52. }
  53.  
  54. void FW_CPostedException::Initialize(FW_SPrivPostedExceptionGlobals& globals)
  55. {
  56. //    globals.gMaxPostedSize = FW_CPrivExceptionRuntime::kDefaultExceptionBufferSize;
  57.     globals.gMaxPostedSize = 1024; // [KVV]
  58.  
  59.     globals.gPostedException = (_FW_XException*) 
  60.                                     ::FW_PrimitiveAllocateBlock(globals.gMaxPostedSize);
  61.     FW_PRIV_ASSERT(globals.gPostedException != 0);
  62.     
  63.     globals.gPending = 0;
  64.  
  65.     FW_PRIV_ASSERT(!globals.gInitialized);
  66.     globals.gInitialized = 1;
  67. }
  68.  
  69. void FW_CPostedException::Terminate()
  70. {
  71.     FW_SPrivPostedExceptionGlobals& globals = GetPostedExceptionGlobals();
  72.     FW_PRIV_ASSERT(globals.gInitialized);
  73.     ::FW_PrimitiveFreeBlock(globals.gPostedException);
  74.     globals.gInitialized = 0;
  75. }
  76.  
  77. void FW_CPostedException::PostException(const _FW_XException& exception)
  78. {
  79.     FW_SPrivPostedExceptionGlobals& globals = GetPostedExceptionGlobals();
  80.     FW_PRIV_ASSERT(globals.gInitialized);
  81.     if (!globals.gPending)
  82.     {
  83.         exception.Copy(globals.gPostedException, globals.gMaxPostedSize);
  84.         globals.gPending = 1;
  85.     }
  86. }
  87.  
  88. void FW_CPostedException::ThrowPostedException()
  89. {
  90.     FW_SPrivPostedExceptionGlobals& globals = GetPostedExceptionGlobals();
  91.     FW_PRIV_ASSERT(globals.gInitialized);
  92.     if (globals.gPending)
  93.     {
  94.         globals.gPending = 0;
  95.         FW_THROW(*globals.gPostedException);
  96.     }
  97. }
  98.